var app = getApp(),
  $ = require("../../utils/httpHelper.js"),
  WxNotificationCenter = require("../../WxNotificationCenter/WxNotificationCenter.js")//通知传参
var wxParse = require("../../wxParse/wxParse.js")
Page({
  data: {
    objarr: [],
    height: '',
    width: '',
    good_info:{},
    currentTab: 0,
    goodsinfo:{},
    isfav:true,
    goods_id:0,
    status:'',
    yhq_status:true,
    goods_gg_status: true,
    time_unit:'',
    num:1,
    speclist:[],
    speclist_array: [],
    coupon_list:[],
    activeid:'',
    sell_p:'',
    sku_id:'',
    add_cart:false,
    comment_list:[],
    showDialog: false,
  },
  onShareAppMessage: function (res) {
    app.shareApp(res)
  },
  onLoad: function (options) {
    var that = this;
    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          height: res.windowHeight,
          width: res.windowWidth
        })
      }
    });
    
    if (!app.check_empty(options.id)){
      var rd_session = wx.getStorageSync('rd_session');
      this.setData({
        goods_id:options.id,
      })
      $.httpPost("good_detail_jifen", { good_id: options.id,rd_session:rd_session}, (data, err) => {
        this.setData({
          good_info:data.data.good_info,
        });
        wxParse.wxParse("about", "html", data.data.good_info.content, this)
      })
    }
    
  },
  todh: function (e) {
    let id = e.currentTarget.dataset.id
    let num = e.currentTarget.dataset.num
    this.setData({
      showDialog: true,
      num: num,
      good_id: id
    })

  },
  checkinfo(name, phone, addr) {
    if (app.check_empty(name) || app.check_empty(phone) || app.check_empty(addr)) {
      wx.showToast({
        title: '不能是空',
      })
      return false
    } else {
      if (app.checkPhone(phone)) {
        return true
      } else {
        wx.showToast({
          title: '手机格式不正确',
        })
        return false
      }

    }
  },
  formSubmit: function (e) {
    console.log('form发生了submit事件，携带数据为：', e.detail.value)
    let name = e.detail.value.username
    let phone = e.detail.value.userphone
    let addr = e.detail.value.addr
    if (this.checkinfo(name, phone, addr)) {
      let params = {
        rd_session: app.globalData.userInfo.rd_session,
        good_id: this.data.good_id,
        name: name,
        phone: phone,
        address: addr
      }
      $.httpPost("get_good_jifen", params, (data, err) => {
        this.setData({
          showDialog: false
        })
        wx.showToast({
          title: data.message,
          duration: 2000,
        })
        if (data.result == 'success') {
          wx.switchTab({
            url: 'pages/mine/mine',
          })
        }
      })
    }
  },
  formReset: function () {
    this.setData({
      showDialog: false
    })
  }
  
});